import { INPUTSEARCH, BTNCONFIRM, DELLISTITEM } from './typeActions.js'
const defaultValue = {
  inputValue : 'Write SomeThing',
  list: [
    '7点半吃完早餐，8点坐公交车来公司上班',
    '9点钟开始打酱油8小时，包括中午休息一个半小时',
    '18点后下半，到家半小时，吃晚饭半小时，休息',
    '22点左右开始养猪，到次日早上7点半继续重复一天生活'
  ]
}

export default (state=defaultValue, actions)=>{
  console.log(state,actions);
  if(actions.type === INPUTSEARCH){
    let newState = JSON.parse(JSON.stringify(state))
    newState.inputValue = actions.value
    return newState
  }else if(actions.type === BTNCONFIRM){
    let newsState = JSON.parse(JSON.stringify(state))
    newsState.list.push(newsState.inputValue)
    newsState.inputValue = ''
    return newsState
  }else if(actions.type === DELLISTITEM){
    let newsState = JSON.parse(JSON.stringify(state))
    newsState.list.splice(actions.index,1)
    return newsState
  }
  return state
}